Skip to main content
Version: 0.5.1

getFasterFuncSync

This method takes any number of arbitrary async functions as input and returns the fastest function in terms of execution time in a Promise.

Params

getFasterFuncSync(inputFunction1,inputFunction2,inputFunction3,...);
  • inputFunctionN... → The functions we want to compare their execution time with each other and return the fastest one

Returns

<Promise> //[AsyncFunction: inpFuncSync2]
  • Promise → Returns the promise that contains the fastest function in terms of execution time

Usage

const inpFuncSync1 = async () => {
return await new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 2000);
});
};

const inpFuncSync2 = async () => {
return await new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 500);
});
};

const inpFuncSync3 = async () => {
return await new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 3000);
});
};

const momentMachine = async () => {
const fasterFunc = await getFasterFuncSync(inpFuncSync1,inpFuncSync2,inpFuncSync3);
console.log(fasterFunc);//[AsyncFunction: inpFuncSync2]
};

momentMachine();